<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button>发送请求</button>
  <button>发送请求2</button>
  <button>发送请求 3</button>
  <script>

    let btn = document.querySelectorAll('button');

    btn[0].onclick = function () {
      //fetch 函数用来发送 AJAX 请求
      fetch('http://api.xiaohigh.com/duanzi')
      .then(response => {
        return response.json();
      }).then(response => {
        console.log(response);
      })
    }

    btn[1].onclick = function () {
      //fetch 函数用来发送 AJAX 请求
      fetch('http://api.xiaohigh.com/duanzi', {
        method: 'post'
      }).then(response => {
        return response.json();
      }).then(response => {
        console.log(response);
      })
    }

    btn[2].onclick = async function(){
      let result = await fetch('http://api.xiaohigh.com/duanzi');
      let body = await result.json();
      console.log(body);
    }

  </script>
</body>

</html>